package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.dto.ArticleStreamMessage;
import com.heima.article.service.IHotArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import sun.security.util.AuthResources_it;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/4/22 22:55
 * @Version 1.0
 */

@Service
public class HotArticleResultListener {

    @Autowired
    private IHotArticleService hotArticleService;

    @KafkaListener(topics = "hot_article_result_topic")
    public void handleMessage(ConsumerRecord<String, String> record) {

        String value = record.value();
        System.out.println("接收到消息" + value);
        //调整HotArticleService更新数据
        ArticleStreamMessage message = JSON.parseObject(value, ArticleStreamMessage.class);
        hotArticleService.update(message);
    }



}
